import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './registerServiceWorker'
import './assets/css/reset.styl'
import './assets/fonts/iconfont.css'
import 'vant/lib/index.css'

// vconsole
// import Vconsole from 'vconsole';
// const vConsole = new Vconsole();
// 公共组件
// import pageTitle from '@/components/Header/Header';
// Vue.component('pageTitle', pageTitle);
// axios
import Axios from 'axios'
import VueAxios from 'vue-axios'
// FastClick IOS 点击事件响应缓慢
import FastClick from 'fastclick'

// vant
import {
  List,
  Tab,
  Tabs,
  Dialog,
  DropdownItem,
  DropdownMenu,
  Loading,
  Notify,
  Skeleton,
  Button
} from 'vant'

Vue.use(VueAxios, Axios)

Vue.use(Notify)
  .use(Tab)
  .use(Tabs)
  .use(List)
  .use(DropdownMenu)
  .use(DropdownItem)
  .use(Skeleton)
  .use(Dialog)
  .use(Loading)
    .use(Button)

// FastClick IOS 点击事件响应缓慢
FastClick.attach(document.body)
let u = navigator.userAgent
FastClick.prototype.focus = function (targetElement) {
  var length
  if ((u.indexOf('iPhone') > -1 || u.indexOf('iPad') > -1) &&
    targetElement.setSelectionRange && targetElement.type.indexOf('date') !==
    0 && targetElement.type !== 'time' && targetElement.type !== 'month') {
    length = targetElement.value.length
    targetElement.focus()
    targetElement.setSelectionRange(length, length)
  } else {
    targetElement.focus()
  }
}

Vue.prototype.$alertWarn = (text, action) => {
  if (!text) return false
  Notify({
    message: text,
    duration: 3000,
    background: '#faa44e',
    onClose () {
      action && action()
    },
  })
  return false
}
Vue.prototype.$alertErr = (text, isBack, action) => {
  Notify({
    message: text ? text : '登录信息有误，请重新登录！',
    duration: 3000,
    background: '#FC703E',
    onClose () {
	    isBack && router.back()
	    action && action()
    },
  })
  return false
}
Vue.prototype.$alertSuc = (text, isBack, action) => {
  Notify({
    message: text ? text : '提交成功！',
    duration: 1000,
    background: '#4771DC',
    onClose () {
	    isBack && router.back()
	    action && action()
    },
  })
  return false
}

Vue.config.productionTip = false

// 控制缓存页面滚动条高度
// 主要是列表 列表均为className='listBox' 无法使用mixin方法
router.beforeEach((to, from, next) => {
  // if (from.meta.keepAlive) {
  //   const $content = document.querySelector('.listBox')
  //   const scrollTop = $content ? $content.scrollTop : 0
  //   // 需要刷新的 重置滚动条高度
  //   const refresh = from.meta.refresh
  //   from.meta.scrollTop = refresh ? 0 : scrollTop
  // }
  next()
})

import Mixin from "@/mixin.js"
// Vue.mixin(Mixin)

let newVue = new Vue({
  data: {},
  mixins: [Mixin],
  created () {},
  router,
  store,
  render: h => h(App),
}).$mount('#app')
